/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package processors;

import containers.Groups;
import containers.TestsTaken;
import java.util.LinkedList;
import readers.QueryStringHandler;
import readers.UserReader;

/**
 * This creates a list of scores for the quizzes a student has taken
 * as the webcomponent uses a different processor this will only be
 * called by students, thus the naming
 * @author Chris
 */
public class processorQuizWords extends processor {
    private String _errMsg;
    processorQuizWords(String query) {
        super(query);
        _errMsg = "<quiz></quiz>";
    }
    
    @Override
    String process() {
        QueryStringHandler qsh = new QueryStringHandler(_queryString);
        String userName = qsh.getElement("userName");
        String teacherName = qsh.getElement("TN");
        String groupName = qsh.getElement("GN");
        String testName = qsh.getElement("TESTN");
        
        if(userName == null || teacherName == null || groupName == null
                || testName == null) {
            return _errMsg;
        }
        LinkedList<String> words = new LinkedList<String>();
        
        if(UserReader.getTest(teacherName, groupName, testName, words)) {
            words.clear();
            return _errMsg;
        }
        
        String results = "<quiz>";
        while(!words.isEmpty()) {
            results += "<word>" + words.getFirst() + "</word>";
            words.removeFirst();
        }
        results += "</quiz>";
        
        return results;
    }
}
